﻿using System;
using System.Data;
using LibDBConnect;

namespace LibDataLayer
{
    public static class DalPosts
    {
        private static readonly SqlHelper Cls = new SqlHelper();
        #region[Get-Data]
        public static DataTable GetPosts(string keywords)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("KEYWORDS", keywords);
            return Cls.GetData("sp_Posts_Get");
        }
        public static DataTable GetPostsEdit(int id)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("Pid", id);
            return Cls.GetData("sp_Posts_Get_Edit");
        }
        public static DataTable GetPostsFillterStatus(int IsActive)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("IsActive", IsActive);
            return Cls.GetData("sp_Posts_Get_FillterStatus");
        }
        public static DataTable GetPostsFillterCategories(int Tid)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("Tid", Tid);
            return Cls.GetData("sp_Posts_Get_FillterCategories");
        }
        public static DataTable GetPostsFillterDate(string DateBegin,string DateEnd)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("DateBegin", DateBegin);
            Cls.AddParameter("EndBegin", DateEnd);
            return Cls.GetData("sp_Posts_Get_FillterDate");
        }
        #endregion

        #region[Insert-Update-Delete]
        public static bool Insert(DTOPosts obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("UserId", obj.UserId);
            Cls.AddParameter("UserIp", obj.UserIp);
            Cls.AddParameter("Message", obj.Message);
            Cls.AddParameter("HideSmiles", obj.HideSmiles);
            Cls.AddParameter("Posted", obj.Posted);
            Cls.AddParameter("EditedBy", obj.EditedBy);
            Cls.AddParameter("Tid", obj.Tid);
            return Cls.ExecuteNonQuery("sp_Posts_Insert");
        }
        public static bool Update(DTOPosts obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("Pid", obj.Pid);
            Cls.AddParameter("UserIp", obj.UserIp);
            Cls.AddParameter("Message", obj.Message);
            Cls.AddParameter("HideSmiles", obj.HideSmiles);
            Cls.AddParameter("Edited", obj.Edited);
            Cls.AddParameter("EditedBy", obj.EditedBy);
            Cls.AddParameter("Tid", obj.Tid);
            return Cls.ExecuteNonQuery("sp_Posts_Update");
        }
        public static bool Delete(DTOPosts obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("Pid ", obj.Pid);
            obj.Msg = Cls.ExecuteNonQueryOutput("sp_Posts_Delete", "@Msg");
            return true;
        }
        public static bool UpdateCheck(DTOPosts obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("Pid", obj.Pid);
            Cls.AddParameter("IsActive", obj.IsActive);
            return Cls.ExecuteNonQuery("sp_Posts_Update_Check");
        }
        #endregion

        #region[Get-Data]
        public static DataTable GetPostsHomePage(string keywords, int Tid)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("KEYWORDS", keywords);
            Cls.AddParameter("Tid", Tid);
            return Cls.GetData("sp_Posts_Get_HomePage");
        }
        public static DataTable GetPostsHomePageFid(string keywords, int Fid)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("KEYWORDS", keywords);
            Cls.AddParameter("Fid", Fid);
            return Cls.GetData("sp_Posts_Get_HomePageFid");
        }
        public static bool InsertHomePage(DTOTopics obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("UserId", obj.UserId);
            Cls.AddParameter("Subject", obj.Subject);
            Cls.AddParameter("Posted", obj.Posted);
            Cls.AddParameter("NumViews", obj.NumViews);
            Cls.AddParameter("Fid", obj.Fid);
            Cls.AddParameter("Message", obj.Message);
            obj.Msg = Cls.ExecuteNonQueryOutput("sp_Topics_Insert_HomePage", "@Msg");
            return true;
        }
        #endregion
    }
    public class DTOPosts
    {
        public string UserId { get; set; }
        public int ? Pid { get; set; }
        public string UserIp { get; set; }
        public string Message { get; set; }
        public int ? HideSmiles { get; set; }
        public DateTime Posted { get; set; }
        public DateTime Edited { get; set; }
        public string EditedBy { get; set; }
        public int ? Tid { get; set; }
        public bool IsActive { get; set; }
        public int Msg { get; set; }
    }
}